package com.jackrain.nea.core.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.HashMap;

@Mapper
@Component
public interface AdRefbyTableMapper {

    @Delete("delete from ad_refbytable where ad_table_id = #{tableId}")
    int delete(long tableId);


    @Select("select AD_REFBY_TABLE_ID,AD_REFBY_COLUMN_ID from ad_refbytable where id = #{id}")
    HashMap getrefbyid(long id);

    @Delete("delete from ad_refbytable where id = #{id}")
    int deletebyid(long id);

    @Insert("insert into AD_REFBYTABLE(ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, AD_TABLE_ID, CREATIONDATE,"
            + "MODIFIEDDATE, OWNERID, MODIFIERID, ORDERNO, FILTER, ASSOCTYPE,AD_REFBY_TABLE_ID, AD_REFBY_COLUMN_ID,"
            + " INLINEMODE) "
            + "select #{newid}, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, #{newTableId}, "
            + "#{now}, #{now}, OWNERID, MODIFIERID, ORDERNO, FILTER,ASSOCTYPE, AD_REFBY_TABLE_ID,"
            + " AD_REFBY_COLUMN_ID, INLINEMODE from AD_REFBYTABLE where id = #{srcid}")
    int clone(@Param("srcid") long srcid,@Param("newid") long newid, @Param("newTableId") long newTableId, @Param("now") Timestamp now);

    @Select("select id from AD_REFBYTABLE where AD_TABLE_ID = #{tableid}")
    long[] selectIdsByTableId(long tableid);
}
